import pagination from '@/views/pagination'  //分页组件
import dialogForm from './edit'
import agentHttp from '@/utils/agentHttp.js'
import {debounce} from '@/utils/index.js'
import {confirm} from '@/utils/confirm'      //二次确认组件
export default {
  name: 'vehicleFollow',
  components:{dialogForm,pagination},
  created(){
      this.seachData();
  },
  data() {
  	return {
      //搜索字段
  		searchForm:{
  		  logisticsFollowStatus:'',
        waitStockStatus:''	
  		},
      //表格字段
      tableData: [{}],
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
        id:""          //请求参数            自定义 例如index或者id
      },
      formLabelWidth:'120px',
      followStatusMap:'',
      waitStatusMap:'',
      resetFormStatus:false        
  	}
  },

  methods: {
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.postJson('adminApi/admin/logistics_trackeinfo/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          if (data.success) {
            this.tableData = data.data.tableData;
            this.followStatusMap = data.data.followStatusMap;
            this.waitStatusMap = data.data.waitStatusMap;
          }
        })
      }
    },
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(),1000);
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    handleSee(index, row){
      this.dialogSendData.isAdd=false;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    handleEdit(index, row){
      this.dialogSendData.isAdd=true;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
    },
    inStock(index, row){
      confirm(()=>{
          agentHttp.putJson('adminApi/admin/logistics_trackeinfo/in_stock/'+row.id).then((data)=>{
              if(data.success){  
                this.seachData();
                this.$message.success(data.data||"准入库成功");                
              } 
          })
        },()=>{
           this.$message.info('已取消准入库'); 
        },"确认准入库吗?")
    }
  }
}
